home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / WANROUTE.{7O < prev    next >
Text File  |  1999-09-17  |  15KB  |  382 lines

  1. /*****************************************************************************
  2. * router.h    Definitions for the WAN Multiprotocol Router Module.
  3. *        This module provides API and common services for WAN Link
  4. *        Drivers and is completely hardware-independent.
  5. *
  6. * Author:    Gene Kozin    <genek@compuserve.com>
  7. *        Jaspreet Singh    <jaspreet@sangoma.com>
  8. *
  9. * Copyright:    (c) 1995-1997 Sangoma Technologies Inc.
  10. *
  11. *        This program is free software; you can redistribute it and/or
  12. *        modify it under the terms of the GNU General Public License
  13. *        as published by the Free Software Foundation; either version
  14. *        2 of the License, or (at your option) any later version.
  15. * ============================================================================
  16. * Nov 06, 1997    Jaspreet Singh    Changed Router Driver version to 1.1 from 1.0
  17. * Oct 20, 1997    Jaspreet Singh    Added 'cir','bc','be' and 'mc' to 'wanif_conf_t'
  18. *                Added 'enable_IPX' and 'network_number' to 
  19. *                'wan_device_t'.  Also added defines for
  20. *                UDP PACKET TYPE, Interrupt test, critical values*                for RACE conditions.
  21. * Oct 05, 1997    Jaspreet Singh    Added 'dlci_num' and 'dlci[100]' to 
  22. *                'wan_fr_conf_t' to configure a list of dlci(s)
  23. *                for a NODE 
  24. * Jul 07, 1997    Jaspreet Singh    Added 'ttl' to 'wandev_conf_t' & 'wan_device_t'
  25. * May 29, 1997     Jaspreet Singh    Added 'tx_int_enabled' to 'wan_device_t'
  26. * May 21, 1997    Jaspreet Singh    Added 'udp_port' to 'wan_device_t'
  27. * Apr 25, 1997  Farhan Thawar   Added 'udp_port' to 'wandev_conf_t'
  28. * Jan 16, 1997    Gene Kozin    router_devlist made public
  29. * Jan 02, 1997    Gene Kozin    Initial version (based on wanpipe.h).
  30. *****************************************************************************/
  31. #ifndef    _ROUTER_H
  32. #define    _ROUTER_H
  33.  
  34. #define    ROUTER_NAME    "wanrouter"    /* in case we ever change it */
  35. #define    ROUTER_VERSION    1        /* version number */
  36. #define    ROUTER_RELEASE    1        /* release (minor version) number */
  37. #define    ROUTER_IOCTL    'W'        /* for IOCTL calls */
  38. #define    ROUTER_MAGIC    0x524D4157L    /* signature: 'WANR' reversed */
  39.  
  40. /* IOCTL codes for /proc/router/<device> entries (up to 255) */
  41. enum router_ioctls
  42. {
  43.     ROUTER_SETUP    = ROUTER_IOCTL<<8,    /* configure device */
  44.     ROUTER_DOWN,                /* shut down device */
  45.     ROUTER_STAT,                /* get device status */
  46.     ROUTER_IFNEW,                /* add interface */
  47.     ROUTER_IFDEL,                /* delete interface */
  48.     ROUTER_IFSTAT,                /* get interface status */
  49.     ROUTER_USER    = (ROUTER_IOCTL<<8)+16,    /* driver-specific calls */
  50.     ROUTER_USER_MAX    = (ROUTER_IOCTL<<8)+31
  51. };
  52.  
  53. /* NLPID for packet encapsulation (ISO/IEC TR 9577) */
  54. #define    NLPID_IP    0xCC    /* Internet Protocol Datagram */
  55. #define    NLPID_SNAP    0x80    /* IEEE Subnetwork Access Protocol */
  56. #define    NLPID_CLNP    0x81    /* ISO/IEC 8473 */
  57. #define    NLPID_ESIS    0x82    /* ISO/IEC 9542 */
  58. #define    NLPID_ISIS    0x83    /* ISO/IEC ISIS */
  59. #define    NLPID_Q933    0x08    /* CCITT Q.933 */
  60.  
  61. /* Miscellaneous */
  62. #define    WAN_IFNAME_SZ    15    /* max length of the interface name */
  63. #define    WAN_DRVNAME_SZ    15    /* max length of the link driver name */
  64. #define    WAN_ADDRESS_SZ    31    /* max length of the WAN media address */
  65.  
  66. /* Defines for UDP PACKET TYPE */
  67. #define UDP_PTPIPE_TYPE     0x01
  68. #define UDP_FPIPE_TYPE        0x02
  69. #define UDP_DRVSTATS_TYPE     0x03
  70. #define UDP_INVALID_TYPE      0x04
  71.  
  72. /* Command return code */
  73. #define CMD_OK        0        /* normal firmware return code */
  74. #define CMD_TIMEOUT    0xFF        /* firmware command timed out */
  75.  
  76. /* UDP Packet Management */
  77. #define UDP_PKT_FRM_STACK    0x00
  78. #define UDP_PKT_FRM_NETWORK    0x01
  79.  
  80. /* Maximum interrupt test counter */
  81. #define MAX_INTR_TEST_COUNTER    100
  82.  
  83. /* Critical Values for RACE conditions*/
  84. #define CRITICAL_IN_ISR        0xA1
  85. #define CRITICAL_INTR_HANDLED    0xB1
  86.  
  87. /****** Data Types **********************************************************/
  88.  
  89. /*----------------------------------------------------------------------------
  90.  * X.25-specific link-level configuration.
  91.  */
  92. typedef struct wan_x25_conf
  93. {
  94.     unsigned lo_pvc;    /* lowest permanent circuit number */
  95.     unsigned hi_pvc;    /* highest permanent circuit number */
  96.     unsigned lo_svc;    /* lowest switched circuit number */
  97.     unsigned hi_svc;    /* highest switched circuit number */
  98.     unsigned hdlc_window;    /* HDLC window size (1..7) */
  99.     unsigned pkt_window;    /* X.25 packet window size (1..7) */
  100.     unsigned t1;        /* HDLC timer T1, sec (1..30) */
  101.     unsigned t2;        /* HDLC timer T2, sec (0..29) */
  102.     unsigned t4;        /* HDLC supervisory frame timer = T4 * T1 */
  103.     unsigned n2;        /* HDLC retransmission limit (1..30) */
  104.     unsigned t10_t20;    /* X.25 RESTART timeout, sec (1..255) */
  105.     unsigned t11_t21;    /* X.25 CALL timeout, sec (1..255) */
  106.     unsigned t12_t22;    /* X.25 RESET timeout, sec (1..255) */
  107.     unsigned t13_t23;    /* X.25 CLEAR timeout, sec (1..255) */
  108.     unsigned t16_t26;    /* X.25 INTERRUPT timeout, sec (1..255) */
  109.     unsigned t28;        /* X.25 REGISTRATION timeout, sec (1..255) */
  110.     unsigned r10_r20;    /* RESTART retransmission limit (0..250) */
  111.     unsigned r12_r22;    /* RESET retransmission limit (0..250) */
  112.     unsigned r13_r23;    /* CLEAR retransmission limit (0..250) */
  113.     unsigned ccitt_compat;    /* compatibility mode: 1988/1984/1980 */
  114. } wan_x25_conf_t;
  115.  
  116. /*----------------------------------------------------------------------------
  117.  * Frame relay specific link-level configuration.
  118.  */
  119. typedef struct wan_fr_conf
  120. {
  121.     unsigned signalling;    /* local in-channel signalling type */
  122.     unsigned t391;        /* link integrity verification timer */
  123.     unsigned t392;        /* polling verification timer */
  124.     unsigned n391;        /* full status polling cycle counter */
  125.     unsigned n392;        /* error threshold counter */
  126.     unsigned n393;        /* monitored events counter */
  127.     unsigned dlci_num;    /* number of DLCs (access node) */
  128.     unsigned  dlci[100];    /* List of all DLCIs */
  129. } wan_fr_conf_t;
  130.  
  131. /*----------------------------------------------------------------------------
  132.  * PPP-specific link-level configuration.
  133.  */
  134. typedef struct wan_ppp_conf
  135. {
  136.     unsigned restart_tmr;    /* restart timer */
  137.     unsigned auth_rsrt_tmr;    /* authentication timer */
  138.     unsigned auth_wait_tmr;    /* authentication timer */
  139.     unsigned mdm_fail_tmr;    /* modem failure timer */
  140.     unsigned dtr_drop_tmr;    /* DTR drop timer */
  141.     unsigned connect_tmout;    /* connection timeout */
  142.     unsigned conf_retry;    /* max. retry */
  143.     unsigned term_retry;    /* max. retry */
  144.     unsigned fail_retry;    /* max. retry */
  145.     unsigned auth_retry;    /* max. retry */
  146.     unsigned auth_options;    /* authentication opt. */
  147.     unsigned ip_options;    /* IP options */
  148. } wan_ppp_conf_t;
  149.  
  150. /*----------------------------------------------------------------------------
  151.  * WAN device configuration. Passed to ROUTER_SETUP IOCTL.
  152.  */
  153. typedef struct wandev_conf
  154. {
  155.     unsigned magic;        /* magic number (for verification) */
  156.     unsigned config_id;    /* configuration structure identifier */
  157.                 /****** hardware configuration ******/
  158.     unsigned ioport;    /* adapter I/O port base */
  159.     unsigned long maddr;    /* dual-port memory address */
  160.     unsigned msize;        /* dual-port memory size */
  161.     int irq;        /* interrupt request level */
  162.     int dma;        /* DMA request level */
  163.     unsigned bps;        /* data transfer rate */
  164.     unsigned mtu;        /* maximum transmit unit size */
  165.         unsigned udp_port;      /* UDP port for management */
  166.     unsigned char ttl;    /* Time To Live for UDP security */
  167.         char interface;        /* RS-232/V.35, etc. */
  168.     char clocking;        /* external/internal */
  169.     char line_coding;    /* NRZ/NRZI/FM0/FM1, etc. */
  170.     char station;        /* DTE/DCE, primary/secondary, etc. */
  171.     char connection;    /* permanent/switched/on-demand */
  172.     unsigned hw_opt[4];    /* other hardware options */
  173.     unsigned char enable_IPX;    /* Enable or Disable IPX */
  174.     unsigned long network_number;    /* Network Number for IPX */
  175.     unsigned reserved[4];
  176.                 /****** arbitrary data ***************/
  177.     unsigned data_size;    /* data buffer size */
  178.     void* data;        /* data buffer, e.g. firmware */
  179.     union            /****** protocol-specific ************/
  180.     {
  181.         wan_x25_conf_t x25;    /* X.25 configuration */
  182.         wan_ppp_conf_t ppp;    /* PPP configuration */
  183.         wan_fr_conf_t fr;    /* frame relay configuration */
  184.     } u;
  185. } wandev_conf_t;
  186.  
  187. /* 'config_id' definitions */
  188. #define    WANCONFIG_X25    101    /* X.25 link */
  189. #define    WANCONFIG_FR    102    /* frame relay link */
  190. #define    WANCONFIG_PPP    103    /* synchronous PPP link */
  191.  
  192. /*
  193.  * Configuration options defines.
  194.  */
  195. /* general options */
  196. #define    WANOPT_OFF    0
  197. #define    WANOPT_ON    1
  198. #define    WANOPT_NO    0
  199. #define    WANOPT_YES    1
  200.  
  201. /* intercace options */
  202. #define    WANOPT_RS232    0
  203. #define    WANOPT_V35    1
  204.  
  205. /* data encoding options */
  206. #define    WANOPT_NRZ    0
  207. #define    WANOPT_NRZI    1
  208. #define    WANOPT_FM0    2
  209. #define    WANOPT_FM1    3
  210.  
  211. /* link type options */
  212. #define    WANOPT_POINTTOPOINT    0    /* RTS always active */
  213. #define    WANOPT_MULTIDROP    1    /* RTS is active when transmitting */
  214.  
  215. /* clocking options */
  216. #define    WANOPT_EXTERNAL    0
  217. #define    WANOPT_INTERNAL    1
  218.  
  219. /* station options */
  220. #define    WANOPT_DTE        0
  221. #define    WANOPT_DCE        1
  222. #define    WANOPT_CPE        0
  223. #define    WANOPT_NODE        1
  224. #define    WANOPT_SECONDARY    0
  225. #define    WANOPT_PRIMARY        1
  226.  
  227. /* connection options */
  228. #define    WANOPT_PERMANENT    0    /* DTR always active */
  229. #define    WANOPT_SWITCHED        1    /* use DTR to setup link (dial-up) */
  230. #define    WANOPT_ONDEMAND        2    /* activate DTR only before sending */
  231.  
  232. /* frame relay in-channel signalling */
  233. #define    WANOPT_FR_ANSI        0    /* ANSI T1.617 Annex D */
  234. #define    WANOPT_FR_Q933        1    /* ITU Q.933A */
  235. #define    WANOPT_FR_LMI        2    /* LMI */
  236.  
  237. /*----------------------------------------------------------------------------
  238.  * WAN Link Status Info (for ROUTER_STAT IOCTL).
  239.  */
  240. typedef struct wandev_stat
  241. {
  242.     unsigned state;        /* link state */
  243.     unsigned ndev;        /* number of configured interfaces */
  244.  
  245.     /* link/interface configuration */
  246.     unsigned connection;    /* permanent/switched/on-demand */
  247.     unsigned media_type;    /* Frame relay/PPP/X.25/SDLC, etc. */
  248.     unsigned mtu;        /* max. transmit unit for this device */
  249.  
  250.     /* physical level statistics */
  251.     unsigned modem_status;    /* modem status */
  252.     unsigned rx_frames;    /* received frames count */
  253.     unsigned rx_overruns;    /* receiver overrun error count */
  254.     unsigned rx_crc_err;    /* receive CRC error count */
  255.     unsigned rx_aborts;    /* received aborted frames count */
  256.     unsigned rx_bad_length;    /* unexpetedly long/short frames count */
  257.     unsigned rx_dropped;    /* frames discarded at device level */
  258.     unsigned tx_frames;    /* transmitted frames count */
  259.     unsigned tx_underruns;    /* aborted transmissions (underruns) count */
  260.     unsigned tx_timeouts;    /* transmission timeouts */
  261.     unsigned tx_rejects;    /* other transmit errors */
  262.  
  263.     /* media level statistics */
  264.     unsigned rx_bad_format;    /* frames with invalid format */
  265.     unsigned rx_bad_addr;    /* frames with invalid media address */
  266.     unsigned tx_retries;    /* frames re-transmitted */
  267.     unsigned reserved[16];    /* reserved for future use */
  268. } wandev_stat_t;
  269.  
  270. /* 'state' defines */
  271. enum wan_states
  272. {
  273.     WAN_UNCONFIGURED,    /* link/channel is not configured */
  274.     WAN_DISCONNECTED,    /* link/channel is disconnected */
  275.     WAN_CONNECTING,        /* connection is in progress */
  276.     WAN_CONNECTED,        /* link/channel is operational */
  277.     WAN_LIMIT        /* for verification only */
  278. };
  279.  
  280. /* 'modem_status' masks */
  281. #define    WAN_MODEM_CTS    0x0001    /* CTS line active */
  282. #define    WAN_MODEM_DCD    0x0002    /* DCD line active */
  283. #define    WAN_MODEM_DTR    0x0010    /* DTR line active */
  284. #define    WAN_MODEM_RTS    0x0020    /* RTS line active */
  285.  
  286. /*----------------------------------------------------------------------------
  287.  * WAN interface (logical channel) configuration (for ROUTER_IFNEW IOCTL).
  288.  */
  289. typedef struct wanif_conf
  290. {
  291.     unsigned magic;            /* magic number */
  292.     unsigned config_id;        /* configuration identifier */
  293.     char name[WAN_IFNAME_SZ+1];    /* interface name, ASCIIZ */
  294.     char addr[WAN_ADDRESS_SZ+1];    /* media address, ASCIIZ */
  295.     unsigned idle_timeout;        /* sec, before disconnecting */
  296.     unsigned hold_timeout;        /* sec, before re-connecting */
  297.     unsigned cir;            /* Committed Information Rate fwd,bwd*/
  298.     unsigned bc;            /* Committed Burst Size fwd, bwd */
  299.     unsigned be;            /* Excess Burst Size fwd, bwd */ 
  300.     char mc;            /* Multicast on or off */
  301.     int reserved[8];        /* reserved for future extensions */
  302. } wanif_conf_t;
  303.  
  304. #ifdef    __KERNEL__
  305. /****** Kernel Interface ****************************************************/
  306.  
  307. #include <linux/fs.h>        /* support for device drivers */
  308. #include <linux/proc_fs.h>    /* proc filesystem pragmatics */
  309. #include <linux/inet.h>        /* in_aton(), in_ntoa() prototypes */
  310. #include <linux/netdevice.h>    /* support for network drivers */
  311.  
  312. /*----------------------------------------------------------------------------
  313.  * WAN device data space.
  314.  */
  315. typedef struct wan_device
  316. {
  317.     unsigned magic;            /* magic number */
  318.     char* name;            /* -> WAN device name (ASCIIZ) */
  319.     void* private;            /* -> driver private data */
  320.                     /****** hardware configuration ******/
  321.     unsigned ioport;        /* adapter I/O port base #1 */
  322.     void * maddr;            /* dual-port memory address */
  323.     unsigned msize;            /* dual-port memory size */
  324.     int irq;            /* interrupt request level */
  325.     int dma;            /* DMA request level */
  326.     unsigned bps;            /* data transfer rate */
  327.     unsigned mtu;            /* max physical transmit unit size */
  328.     unsigned udp_port;              /* UDP port for management */
  329.         unsigned char ttl;        /* Time To Live for UDP security */
  330.     unsigned enable_tx_int;     /* Transmit Interrupt enabled or not */
  331.     char interface;            /* RS-232/V.35, etc. */
  332.     char clocking;            /* external/internal */
  333.     char line_coding;        /* NRZ/NRZI/FM0/FM1, etc. */
  334.     char station;            /* DTE/DCE, primary/secondary, etc. */
  335.     char connection;        /* permanent/switched/on-demand */
  336.     unsigned hw_opt[4];        /* other hardware options */
  337.     unsigned char enable_IPX;    /* Enable or Disable IPX */
  338.     unsigned long network_number;    /* Network Number for IPX */
  339.                     /****** status and statistics *******/
  340.     char state;            /* device state */
  341.     unsigned modem_status;        /* modem status */
  342.     struct enet_statistics stats;    /* interface statistics */
  343.     unsigned reserved[16];        /* reserved for future use */
  344.     unsigned critical;        /* critical section flag */
  345.                     /****** device management methods ***/
  346.     int (*setup) (struct wan_device* wandev, wandev_conf_t* conf);
  347.     int (*shutdown) (struct wan_device* wandev);
  348.     int (*update) (struct wan_device* wandev);
  349.     int (*ioctl) (struct wan_device* wandev, unsigned cmd,
  350.         unsigned long arg);
  351.     int (*new_if) (struct wan_device* wandev, struct device* dev,
  352.         wanif_conf_t* conf);
  353.     int (*del_if) (struct wan_device* wandev, struct device* dev);
  354.                     /****** maintained by the router ****/
  355.     struct wan_device* next;    /* -> next device */
  356.     struct device* dev;        /* list of network interfaces */
  357.     unsigned ndev;            /* number of interfaces */
  358.     struct proc_dir_entry dent;    /* proc filesystem entry */
  359. } wan_device_t;
  360.  
  361. /* Public functions available for device drivers */
  362. extern int register_wan_device(wan_device_t* wandev);
  363. extern int unregister_wan_device(char* name);
  364. unsigned short wanrouter_type_trans(struct sk_buff* skb, struct device* dev);
  365. int wanrouter_encapsulate(struct sk_buff* skb, struct device* dev);
  366.  
  367. /* Proc interface functions. These must not be called by the drivers! */
  368. extern int wanrouter_proc_init (void);
  369. extern void wanrouter_proc_cleanup (void);
  370. extern int wanrouter_proc_add (wan_device_t* wandev);
  371. extern int wanrouter_proc_delete (wan_device_t* wandev);
  372. extern int wanrouter_ioctl(
  373.     struct inode* inode, struct file* file,
  374.     unsigned int cmd, unsigned long arg)
  375. ;
  376.  
  377. /* Public Data */
  378. extern wan_device_t* router_devlist;    /* list of registered devices */
  379.  
  380. #endif    /* __KERNEL__ */
  381. #endif    /* _ROUTER_H */
  382.